﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MiniCPU.Entities
{
    /// <summary>
    /// Clock static entity.
    /// </summary>
    public class Clock
    {
        /// <summary>
        /// Clock Pulse Handler.
        /// </summary>
        public delegate void ClockPulseHandler();

        /// <summary>
        /// Clock Propagation handler.
        /// </summary>
        public delegate void ClockPropagationHandler();

        /// <summary>
        /// Occurs when [clock ticked].
        /// </summary>
        public static event ClockPulseHandler ClockTicked;

        /// <summary>
        /// Occurs when [clock propagated].
        /// </summary>
        public static event ClockPropagationHandler ClockPropagated;

        /// <summary>
        /// Ticks this clock.
        /// </summary>
        public static void Tick()
        {
            if (ClockTicked != null)
            {
                ClockTicked();
            }

            if (ClockPropagated != null)
            {
                ClockPropagated();
            }
        }

        /// <summary>
        /// Propagates the clock.
        /// </summary>
        public static void Propagate()
        {
            if (ClockPropagated != null)
            {
                ClockPropagated();
            }
        }
    }
}
